package cn.howxu.yichen_ovo.event;

import cn.howxu.yichen_ovo.YiChenOVO;
import cn.howxu.yichen_ovo.datagen.*;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraftforge.common.data.ForgeAdvancementProvider;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Collections;
import java.util.List;
import java.util.Set;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class DataGenerators {
    @SubscribeEvent
    public static void gatherData(GatherDataEvent event) {
        var generator = event.getGenerator();
        var existingFileHelper = event.getExistingFileHelper();
        var pack = generator.getPackOutput();
        var vanillaPack = generator.getVanillaPack(true);
        var registries = event.getLookupProvider();
        
        generator.addProvider(event.includeClient(), new ItemModelGenerator(pack, existingFileHelper));
        generator.addProvider(event.includeClient(), new BlockStateGenerator(pack, existingFileHelper));
        generator.addProvider(event.includeServer(), new RecipesGenerator(pack));
        generator.addProvider(event.includeServer(), new LootTableProvider(pack, Set.of(),
                List.of(new LootTableProvider.SubProviderEntry(LootTableGenerator.BlockLootTables::new, LootContextParamSets.BLOCK))));
        var blockTagsProvider = vanillaPack.addProvider(packOutput ->
                new BlockTagGenerator(packOutput, registries, YiChenOVO.MODID, existingFileHelper));
        vanillaPack.addProvider(packOutput ->
                new ItemTagGenerator(packOutput,registries, blockTagsProvider.contentsGetter(), YiChenOVO.MODID, existingFileHelper));
        generator.addProvider(true, new ForgeAdvancementProvider(
                pack, registries, existingFileHelper,
                Collections.singletonList(new AdvanGenerator())
        ));
    }
}
